package com.bdzl.admin.controller.data;

import java.util.List;
import java.util.Map;

import com.bdzl.admin.service.data.EnterpriseHolderService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.data.EnterpriseHolderDO;
import com.bdzl.pub.util.file.OssUploadFileUtil;
import com.bdzl.pub.vo.EnterpriseVO;
import com.github.pagehelper.PageHelper;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import com.bdzl.pub.entity.data.EnterpriseDO;
import com.bdzl.admin.service.data.EnterpriseService;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;

/**
 * 企业基础信息表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 13:57:43
 */
 
@Controller
@RequestMapping("/bdzl/enterprise")
public class EnterpriseController extends BaseController {
	@Autowired
	private EnterpriseService enterpriseService;
	@Autowired
	private EnterpriseHolderService enterpriseHolderService;
	
	@GetMapping()
	String Enterprise(){
	    return "bdzl/enterprise/enterprise";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<EnterpriseDO> enterpriseList = enterpriseService.list(query);
		int total = enterpriseService.count(query);
		PageUtils pageUtils = new PageUtils(enterpriseList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/enterprise/add";
	}

	@GetMapping("/edit/{entId}")
	@ResponseBody
	R edit(@PathVariable("entId") Integer entId){
		EnterpriseDO enterprise = enterpriseService.get(entId);
	    return R.ok(enterprise);
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save(@RequestBody EnterpriseDO enterprise){
		if(enterpriseService.save(enterprise)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( EnterpriseDO enterprise){
		enterpriseService.update(enterprise);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer entId){
		if(enterpriseService.remove(entId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] entIds){
		enterpriseService.batchRemove(entIds);
		return R.ok();
	}

	/**
	 * 企业信息 与 股东信息 查询
	 */
	@ResponseBody
	@GetMapping("/enterpriseAndHolder")
	public PageUtils enterpriseAndHolder(@RequestParam Map<String, Object> params){
		//使用分页插件
		//传入查询的页码，以及显示的条数
		//查询列表数据
		Query query = new Query(params);
		List<EnterpriseVO> enterpriseVOList = enterpriseService.enterpriseAndHolder(query);

		int total = enterpriseService.enterpriseAndHoldercount(query);
		PageUtils pageUtils = new PageUtils(enterpriseVOList, total);
		return pageUtils;
	}

	/**
	 * 修改企业信息 和 股东信息
	 */
	@ResponseBody
	@PostMapping("/updateEnterpriseAndHolder")
	public R  updateEnterpriseAndHolder(@RequestBody EnterpriseVO enterpriseVO){
		enterpriseService.updateEnterpriseAndHolder(enterpriseVO,super.getUserId());
		return R.ok();
	}


}
